
/********************************

Generating Figures and Tables for manuscript:  

Title: Son Preference and Maternal Health: A Cross-Cultural and Temporal Analysis Economic Development and Cultural Change
Ref: MS 24029R1
Economic Development and Cultural Change
Author: Neha Agarwal and Annamaria Milazzo

* This version: September, 2025

*********************************/

clear all 
set more off
set maxvar 7000



global output_latex "C:\Users\agane86p\OneDrive - University of Otago\Documents\Neha\DHS data\sexratio_paper\latex\EDCC_SubmissionFinal"
global data "C:\Users\agane86p\OneDrive - University of Otago\Documents\Neha\DHS data\sexratio_paper\Data files-sex ratio"

global contr_noht       urban agefb age agesq eduyrs               i.year  i.CN
 
global contr            urban agefb age agesq eduyrs resp_ht       i.year  i.CN 
 
global contr_noed       urban agefb age agesq        resp_ht       i.year  i.CN 

global contr_noht_noyr urban agefb age agesq eduyrs i.CN



*============================
*
***         FIGURES       ***
*
*============================

*---------------
*** FIGURE 1 ***
*---------------
use "$data\master_corr_sb.dta", clear
keep if befaft2000==1
 count
 * 2,482,968
 
gen srlb_c=.
gen se_c=.

levelsof Code, local(cty)


foreach i of local cty{
    su lg  if   (wantsnomore==1|femster==1|infert==1) & Code=="`i'"  [aw=dw]
	 replace srlb_c=r(mean) if Code=="`i'"
	}

tabstat srlb_c  lg_c1, by(CountryName)
 
collapse srlb_c  sptotal_sg_c, by (CountryName Code)

collapse (mean) srlb_mean=srlb_c (sem) srlb_se = srlb_c  (sd) srlb_sd = srlb_c, by(sptotal_sg_c) 
gen upper= srlb_mean+(1.96* srlb_se)
gen lower= srlb_mean-(1.96* srlb_se)

gen srlb_mean2=srlb_mean
format srlb_mean2 %4.3f

twoway  (rcap lower upper sptotal_sg_c, lcolor(black)) ///
        (scatter srlb_mean sptotal_sg_c,  mlabel(srlb_mean2) mlabposition(1) mlabcolor(black) mcolor(black)  ), ///
		yline(0.489, lwidth(6) lc(gs15) lp(solid))  xlabel(0(1)5.3) legend(off) ytitle("Mean SRLB") xtitle("# dimensions indicating son preference")
		
		
		graph export  "$output_latex\srlb.eps", replace

*---------------
*** FIGURE 2 ***
*---------------
 use "$data\master_corr_sb.dta", clear
 keep if befaft2000==1
 count
 * 2,482,968
 
 
label define  sp_sb_sg_c 1 "a) High SonPref-Low MatCare" 2 "b) Low SonPref-High MatCare" 3 "c) Low SonPref-Low MatCare" 4 "d) High SonPref-High MatCare", replace
label values sp_sb_sg_c sp_sb_sg_c 
tab sp_sb_sg_c 

twoway (lpolyci fg tdgr if tdgr<=25 [aw=dw],by(sp_sb_sg_c,note("")  legend(position(6))) ///
		bw(7) clc(black) ciplot(rline) clwidth(thick) acolor(black) alp(shortdash)), ///
      	xtitle("Time since first delivery")   legend(order(1 "95% CIs" 2 "share with first-born girls") rows(1) ) ///
		ytitle("Share with first-born girls")  xlabel(0(5)25) ///
		yline(0.489, lwidth(13) lc(gs15) lp(solid)) ylabel(0.475(0.005)0.495)
graph export  "$output_latex\share_main_tdgr.eps", replace


*---------------
*** FIGURE 3, 4 panels ***
*---------------

twoway  (lpolyci fg tdgr if tdgr<=25 & yr2==1 & befaft2000==1 & sp_sb_sg_c==1 [aw=dw], ///
		bw(6) clc(black)  ciplot(rline) clwidth(thick) acolor(black)alp(shortdash) ) ///
		(lpolyci fg tdgr if tdgr<=25 & yr2==2 & befaft2000==1 & sp_sb_sg_c==1 [aw=dw], ///
		bw(6) clc(black) ciplot(rline) clwidth(thick) clpattern (longdash) acolor(black) alp(shortdash) ), ///
		legend(position(6)) xtitle("Time since first delivery")   ///
		legend(order(1 "95% CIs" 2 "Survey in 1990s"  4 "Survey in 2000-18") rows(1)) ///
		ytitle("Share with first-born girls")  ylabel(0.47(0.005)0.495) yline(0.489, lwidth(20) lc(gs15) lp(solid)) title("Panel A")

		graph export  "$output_latex\share_gr1_by_yr2tdgr.eps", replace


* by woman's age, only HH group
twoway  (lpolyci fg age if age>=20 & yr2==1 & befaft2000==1 & sp_sb_sg_c==1 [aw=dw], ///
		bw(6) clc(black)  ciplot(rline) clwidth(thick) acolor(black)  alp(shortdash) ) ///
		(lpolyci fg age if age>=20 & yr2==2 & befaft2000==1 & sp_sb_sg_c==1 [aw=dw], ///
		bw(6) clc(black) ciplot(rline) clwidth(thick) clpattern (longdash) acolor(black) alp(shortdash) ), ///
		legend(position(6)) 	xtitle("Age")   ///
		legend(order(1 "95% CIs" 2 "Survey in 1990s"  4 "Survey in 2000-18") rows(1)) ///
		ytitle("Share with first-born girls")  ylabel(0.47(0.005)0.495) yline(0.489, lwidth(20) lc(gs15) lp(solid))	title("Panel B")
graph export  "$output_latex\share_gr1_by_yr2.eps", replace


* by woman's birth year, only HH group
twoway (lpolyci fg birthyr if birthyr>=1950                  & yr2==1 & befaft2000==1 & sp_sb_sg_c==1 [aw=dw], ///
		bw(6) clc(black) ciplot(rline) clwidth(thick) acolor(black) alp(shortdash))  ///
		(lpolyci fg birthyr if birthyr>=1955 & birthyr<=1995 & yr2==2 & befaft2000==1 & sp_sb_sg_c==1 [aw=dw], ///
		bw(6) clc(black) ciplot(rline) clwidth(thick) clpattern (longdash) acolor(black) alp(shortdash)), ///
      	xtitle("Woman's birthyr")    legend(order(1 "95% CIs" 2 "Survey in 1990s" 4 "Survey in 2000-18" ) rows(1) pos(6)) ///
		ytitle("Share with first-born girls")  ylabel(0.47(0.005)0.495) 	xlabel(1950(10)2000) yline(0.489, lwidth(20) lc(gs15) lp(solid))	  title("Panel C")
	
graph export  "$output_latex\share_gr1_by_byr2.eps", replace



* by 1st child's birth year, only HH group
twoway (lpolyci fg birthyrfch if birthyrfch>=1965 & yr2==1 & befaft2000==1 & sp_sb_sg_c==1 [aw=dw], ///
		bw(6) clc(black) ciplot(rline) clwidth(thick) acolor(black) alp(shortdash)) ///
	   (lpolyci fg birthyrfch if birthyrfch>=1975 & yr2==2 & befaft2000==1 & sp_sb_sg_c==1 [aw=dw], ///
	   bw(6) clc(black) ciplot(rline) clwidth(thick) clpattern (longdash) acolor(black) alp(shortdash)), ///
      	xtitle("First child's birthyr")    legend(order(1 "95% CIs" 2 "Survey in 1990s" 4 "Survey in 2000-18" ) rows(1)pos(6)) ///
		ytitle("Share with first-born girls")  	xlabel(1965(10)2015) yline(0.489, lwidth(16) lc(gs15) lp(solid)) title("Panel D") ylabel(0.465(0.01)0.495)	
		
graph export  "$output_latex\share_gr1_by_byr2ch.eps", replace


*-----------------------------
*** FIGURE 4, by education ***
*-----------------------------

twoway (lpolyci fg tdgr if tdgr<=25 & edu==0 & sp_sb_sg_c==1 [aw=dw], bw(6) clc(black) ciplot(rline) clwidth(thick) acolor(black) alp(shortdash)) ///
       (lpolyci fg tdgr if tdgr<=25 & edu==1 & sp_sb_sg_c==1 [aw=dw], bw(6) clc(black)ciplot(rline) clwidth(thick) clpattern (longdash) acolor(black) alp(shortdash)), ///
		xtitle("Time since first delivery")   xlabel(0(5)25) legend(order(1 "95% CI" 2 "eduyrs==0" 4 "eduyrs>0") rows(1)pos(6)) ///
		ytitle("Share with first-born girls",size(small))  title( "")  yline(0.489, lwidth(20) lc(gs15) lp(solid)) ylabel(0.465(0.01)0.495)	

graph export  "$output_latex\share_byedu.eps", replace

*----------------
*** FIGURE 5  ***
*----------------

tab sp_sb_sg_c
gen sp_sb_sg_c_an=.
replace sp_sb_sg_c_an=1 if sp_sb_sg_c==1
replace sp_sb_sg_c_an=2 if sp_sb_sg_c==3
replace sp_sb_sg_c_an=3 if sp_sb_sg_c==4

label define  sp_sb_sg_c_an 1 "High SonPref-Low MatCare" 2 "Low SonPref-Low MatCare" 3 "High SonPref-High MatCare", replace
label values sp_sb_sg_c_an sp_sb_sg_c_an
tab sp_sb_sg_c_an



twoway (lpolyci  sevmodanemic td if fg==1 &td<300   [aw=dw], bw(30) clc(black) ciplot(rline) clwidth(thick) acolor(black) alp(shortdash)) ///
       (lpolyci  sevmodanemic td if fg==0 &td<300   [aw=dw], bw(30) clc(black)ciplot(rline) clwidth(thick) clpattern(longdash) acolor(black) alp(shortdash)), ///
	   by(sp_sb_sg_c_an, rows(1) note("") legend(position(6))) ///
		xtitle("Months after delivery of the first child") ytitle("% of moderately or severely anemic women") ///
		xlabel(0(100)300) legend(order(1 "95% CIs" 2 "first-born girl" 4 "first-born boy" ) rows(1) position(6)) 
graph export  "$output_latex\sevmodanemia_bygr.eps", replace


*----------------
*** FIGURE 6  ***, sevmodanemia by edu
*----------------
 
twoway 	(lpolyci  sevmodanemic td if fg==1 &td<300  & sp_sb_sg_c==1   [aw=dw], bw(35) clc(black) ciplot(rline) clwidth(thick) acolor(black) alp(shortdash)) ///
       (lpolyci  sevmodanemic td if fg==0 &td<300  & sp_sb_sg_c==1   [aw=dw], bw(35) clc(black)ciplot(rline) clwidth(thick) clpattern(longdash) acolor(black) alp(shortdash)), by(edu,note("")legend(position(6))) ///
		xtitle("Months after delivery of the first child") ytitle("% of moderately or severely anemic women") legend(order(1 "95% CIs" 2 "first-born girl" 4 "first-born boy" ) rows(1)) ///
		title("High SP and Low MatCare")  
graph export  "$output_latex\share_anemia_byedu.eps", replace

*----------------
*** FIGURE 7  ***, sevmodanemia by time since birth
*----------------
*** graphing effect by TD for fg, sg, tg***

gen fg_0=fg
gen fg_1=fg
gen fg_2=fg
gen fg_3=fg
gen fg_4=fg

gen sg_0=sg
gen sg_1=sg
gen sg_2=sg
gen sg_3=sg
gen sg_4=sg

gen tg_0=tg
gen tg_1=tg
gen tg_2=tg
gen tg_3=tg
gen tg_4=tg

lab var fg_0 "overall"
lab var fg_1 "< 1 year"
lab var fg_2 "1-4 years"
lab var fg_3 "5-14 years"
lab var fg_4 ">= 15 years"

lab var sg_0 "overall"
lab var sg_1 "< 1 year"
lab var sg_2 "1-4 years"
lab var sg_3 "5-14 years"
lab var sg_4 ">= 15 years"

lab var tg_0 "overall"
lab var tg_1 "< 1 year"
lab var tg_2 "1-4 years"
lab var tg_3 "5-14 years"
lab var tg_4 ">= 15 years"

estimates clear



reg sevmodanemic fg_0 $contr [pw=dw] if sp_sb_sg_c==1 , vce(robust)
estimates store fg_0
reg sevmodanemic fg_1 $contr [pw=dw] if sp_sb_sg_c==1 & td<12 , vce(robust)
estimates store fg_1
reg sevmodanemic fg_2 $contr [pw=dw] if sp_sb_sg_c==1 & tdgr>=1 & tdgr<=4, vce(robust)
estimates store fg_2
reg sevmodanemic fg_3 $contr [pw=dw] if sp_sb_sg_c==1 & tdgr>=5 & tdgr<=14 , vce(robust)
estimates store fg_3
reg sevmodanemic fg_4 $contr [pw=dw] if sp_sb_sg_c==1 & tdgr>=15 , vce(robust)
estimates store fg_4

reg sevmodanemic sg_0 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 , vce(robust)
estimates store sg_0
reg sevmodanemic sg_1 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 & tsd<12 , vce(robust)
estimates store sg_1
reg sevmodanemic sg_2 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 & tdgr_s>=1 & tdgr_s<=4, vce(robust)
estimates store sg_2
reg sevmodanemic sg_3 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 & tdgr_s>=5 & tdgr_s<=14 , vce(robust)
estimates store sg_3
reg sevmodanemic sg_4 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 & tdgr_s>=15 , vce(robust)
estimates store sg_4

reg sevmodanemic tg_0 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 , vce(robust)
estimates store tg_0
reg sevmodanemic tg_1 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 & ttd<12 , vce(robust)
estimates store tg_1
reg sevmodanemic tg_2 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 & tdgr_t>=1 & tdgr_t<=4, vce(robust)
estimates store tg_2
reg sevmodanemic tg_3 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 & tdgr_t>=5 & tdgr_t<=14 , vce(robust)
estimates store tg_3
reg sevmodanemic tg_4 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 & tdgr_t>=15 , vce(robust)
estimates store tg_4


coefplot (fg_0, mcolor(black) ciopts(lcolor(black black) )) (fg_1, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(fg_2, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(fg_3, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(fg_4, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(sg_0, mcolor(black) ciopts(lcolor(black black))) (sg_1 , mcolor(gs8) ciopts(lcolor(gs8 gs8))) ///
	(sg_2, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(sg_3, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(sg_4, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(tg_0, mcolor(black) ciopts(lcolor(black black)))  (tg_1, mcolor(gs8) ciopts(lcolor(gs8 gs8))) ///
	(tg_2, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(tg_3, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(tg_4, mcolor(gs8) ciopts(lcolor(gs8 gs8))), vertical legend(off) /// 
	xlabel(,alternate) ///
	keep(fg_0 fg_1 fg_2 fg_3 fg_4 sg_0 sg_1 sg_2 sg_3 sg_4 tg_0 tg_1 tg_2 tg_3 tg_4) ///
	yline(0)  coeflabels(, wrap(14) labsize(*.6)) levels(95 90) ylabel(-0.05(0.01)0.04) xtitle(" " "length of time after the birth of first, second, and third girl", size(small)) ///
	ytitle("probability of being moderately or severely anemic (girl-boy)" " ", size(small))  ///
	headings(fg_0 fg_1 fg_2 fg_3 fg_4="first girl" sg_0 sg_1 sg_2 sg_3 sg_4="second girl|G"  tg_0 tg_1 tg_2 tg_3 tg_4="third girl|GG",labsize(small) labgap(-130)) 	groups(fg_0 fg_1 fg_2 fg_3 fg_4="first girl" sg_0 sg_1 sg_2 sg_3 sg_4="second girl|G"  tg_0 tg_1 tg_2 tg_3 tg_4="third girl|GG" ,labsize(small) )  	

graph export  "$output_latex\sevmodanemia_gr1_td.eps", replace


*----------------------------------------------------------------
*** FIGURE 8 and Figure A.8  ***, sevmodanemia by time since birth
*----------------------------------------------------------------

estimates clear
gen spacing1_2_div=spacing1_2/10

gen fg1=fg
gen fg2=fg
gen fg3=fg
gen fg4=fg
gen fg5=fg
gen fg6=fg

gen fg1_ed=fg
gen fg2_ed=fg
gen fg3_ed=fg
gen fg4_ed=fg
gen fg5_ed=fg

gen fg1_noed=fg
gen fg2_noed=fg
gen fg3_noed=fg
gen fg4_noed=fg
gen fg5_noed=fg

 
		forval i=1/4 {

estimates clear

reg bornkids i.fg1##c.year $contr_noht if sp_sb_sg_c==`i'  & (wantsnomore==1|femster==1|infert==1) [pw=dw], r	
estimates store bornkids
reg wantsmore i.fg2##c.year $contr_noht  if sp_sb_sg_c==`i'    [pw=dw], r	
estimates store wantsmore
reg sg i.fg3##c.year $contr_noht  if v201>=2 & sp_sb_sg_c==`i'    [pw=dw], r	
estimates store sg
reg contrac i.fg4##c.year  $contr_noht  if sp_sb_sg_c==`i'   [pw=dw], r	
estimates store contrac
reg spacing1_2_div i.fg5##c.year  $contr_noht  if  v201>=2 & sp_sb_sg_c==`i'  [pw=dw], r	
estimates store spacing1_2
reg sevmodanemic i.fg6##c.year resp_ht $contr  if  sp_sb_sg_c==`i' [pw=dw], r	
estimates store sevmodanemic

reg bornkids i.fg1##c.year $contr_noht if sp_sb_sg_c==`i'  & (wantsnomore==1|femster==1|infert==1) & edu==0  [pw=dw], r	
estimates store bornkids_noed
reg wantsmore i.fg2##c.year $contr_noht  if sp_sb_sg_c==`i'  & edu==0  [pw=dw], r	
estimates store wantsmore_noed
reg sg i.fg3##c.year $contr_noht  if v201>=2 & sp_sb_sg_c==`i'  & edu==0   [pw=dw], r	
estimates store sg_noed
reg contrac i.fg4##c.year  $contr_noht  if sp_sb_sg_c==`i'  & edu==0   [pw=dw], r	
estimates store contrac_noed
reg spacing1_2_div i.fg5##c.year  $contr_noht  if  v201>=2 & sp_sb_sg_c==`i'  & edu==0   [pw=dw], r	
estimates store spacing1_2_noed
reg sevmodanemic i.fg6##c.year  $contr resp_ht if  sp_sb_sg_c==`i' & edu==0  [pw=dw], r	
estimates store sevmodanemic_noed


reg bornkids i.fg1##c.year $contr_noht if sp_sb_sg_c==`i'  & (wantsnomore==1|femster==1|infert==1) & edu==1  [pw=dw], r	
estimates store bornkids_ed
reg wantsmore i.fg2##c.year $contr_noht  if sp_sb_sg_c==`i'  & edu==1   [pw=dw], r	
estimates store wantsmore_ed
reg sg i.fg3##c.year $contr_noht  if v201>=2 & sp_sb_sg_c==`i'  & edu==1    [pw=dw], r	
estimates store sg_ed
reg contrac i.fg4##c.year  $contr_noht  if sp_sb_sg_c==`i'  & edu==1 [pw=dw], r	
estimates store contrac_ed
reg spacing1_2_div i.fg5##c.year  $contr_noht  if  v201>=2 & sp_sb_sg_c==`i'  & edu==1    [pw=dw], r	
estimates store spacing1_2_ed
reg sevmodanemic i.fg6##c.year  $contr resp_ht if  sp_sb_sg_c==`i' & edu==1   [pw=dw], r	
estimates store sevmodanemic_ed


coefplot 	(sevmodanemic bornkids wantsmore sg contrac spacing1_2 , label(full sample) msymbol(O) levels(95 90)  mcolor(black) ciopts(lcolor(black black))) ///
			(sevmodanemic_noed bornkids_noed wantsmore_noed sg_noed contrac_noed spacing1_2_noed , label(eduyrs=0) msymbol(S) levels(95 90) mcolor(gs8) ciopts(lcolor(gs8 gs8))) ///
			(sevmodanemic_ed bornkids_ed wantsmore_ed sg_ed contrac_ed spacing1_2_ed , label(eduyrs>0) msymbol(D) levels(95 90) mcolor(gs8) ciopts(lcolor(gs8 gs8))), legend(rows(1) pos(6)) xline(0) ///
			keep(1.fg1#c.year 1.fg1_ed#c.year 1.fg1_noed#c.year  1.fg2#c.year  1.fg2_ed#c.year   1.fg2_noed#c.year 1.fg3#c.year 1.fg3_ed#c.year   1.fg3_noed#c.year  1.fg4#c.year  1.fg4_ed#c.year   1.fg4_noed#c.year 1.fg5#c.year  1.fg5_ed#c.year   1.fg5_noed#c.year  1.fg6#c.year  1.fg6_ed#c.year   1.fg6_noed#c.year  )  ///
			coeflabels(1.fg1#c.year="# children ever born" 1.fg2#c.year="wants more children" 1.fg3#c.year="second-born girl" 1.fg4#c.year="using contraception" ///
			1.fg5#c.year="spacing bw 1st and 2nd child" 1.fg6#c.year="moderately or severely anemic", wrap(20) labsize(*.7)) ///
			ytitle("coefficient on (first-born*year)" " " ,size(small))
graph export  "$output_latex\overtime_gr`i'.eps", replace

		}

*==========================
 *
 ***       TABLES      ***
 *
*==========================
 
*--------------
*** TABLE 1 ***, Selected summary statistics by sex of the first-born child, by country group
*--------------

		forval i=1/4 {

	foreach var of varlist edu eduyrs  age agefb termpreg sg contrac wantsmore spacing1_2 anemic sevmodanemic{
	 
capture reg `var' fg [pw=dw] if sp_sb_sg_c==`i', vce(robust)
outreg2 using "$output_latex\SS_bygr.xls", nolabel ctitle(`var', sp_sb_sg_c `i', all) se bdec(3) rdec(3) append
}
}
 
reg bornkids fg [pw=dw] if sp_sb_sg_c==1 & (wantsnomore==1|femster==1|infert==1), vce(robust)
reg bornkids fg [pw=dw] if sp_sb_sg_c==2 & (wantsnomore==1|femster==1|infert==1), vce(robust)
reg bornkids fg [pw=dw] if sp_sb_sg_c==3 & (wantsnomore==1|femster==1|infert==1), vce(robust)
reg bornkids fg [pw=dw] if sp_sb_sg_c==4 & (wantsnomore==1|femster==1|infert==1), vce(robust)



*-------------------
***   TABLE 2    ***, Selected summary statistics by sex of the first-born child, HL group, by length of time since first birth
*-------------------
	forval i=1/4 {

	foreach var of varlist edu eduyrs age agefb  termpreg  contrac wantsmore  anemic sevmodanemic{
	 	
capture reg `var' fg [pw=dw] if sp_sb_sg_c==`i' & td<12, vce(robust)
outreg2 using "$output_latex\SS_bygr_td_yr.xls", nolabel ctitle(`var', sp_sb_sg_c `i', td<12m) se bdec(3) rdec(3) append

capture reg `var' fg [pw=dw] if sp_sb_sg_c==`i' & tdgr>=1 & tdgr<=4, vce(robust)
outreg2 using "$output_latex\SS_bygr_td_yr.xls", nolabel ctitle(`var', sp_sb_sg_c `i', 1-4y) se bdec(3) rdec(3) append

capture reg `var' fg [pw=dw] if sp_sb_sg_c==`i' & tdgr>=5 & tdgr<=14, vce(robust)
outreg2 using "$output_latex\SS_bygr_td_yr.xls", nolabel ctitle(`var', sp_sb_sg_c `i', 5-14y) se bdec(3) rdec(3) append

capture reg `var' fg [pw=dw] if sp_sb_sg_c==`i' & tdgr>=15, vce(robust)
outreg2 using "$output_latex\SS_bygr_td_yr.xls", nolabel ctitle(`var', sp_sb_sg_c `i', 15y+) se bdec(3) rdec(3) append

}
}
*** ONLY second-girl and spacing
		forval i=1/4 {
	foreach var of varlist spacing1_2 sg {

capture reg `var' fg [pw=dw] if sp_sb_sg_c==`i' & tdgr>=1 & tdgr<=4 & v201>=2, vce(robust)
outreg2 using "$output_latex\SS_bygr_td_spac_yr.xls", nolabel ctitle(`var', sp_sb_sg_c `i', 1-4y) se bdec(3) rdec(3) append

capture reg `var' fg [pw=dw] if sp_sb_sg_c==`i' & tdgr>=5 & tdgr<=14 & v201>=2, vce(robust)
outreg2 using "$output_latex\SS_bygr_td_spac_yr.xls", nolabel ctitle(`var', sp_sb_sg_c `i', 5-14y) se bdec(3) rdec(3) append

capture reg `var' fg [pw=dw] if sp_sb_sg_c==`i' & tdgr>=15 & v201>=2, vce(robust)
outreg2 using "$output_latex\SS_bygr_td_spac_yr.xls", nolabel ctitle(`var', sp_sb_sg_c `i', 15y+) se bdec(3) rdec(3) append

}
}

 
  reg bornkids fg [pw=dw] if sp_sb_sg_c==1 & tdgr>=1 & tdgr<=4 & (wantsnomore==1|femster==1|infert==1), vce(robust) 
 
  reg bornkids fg [pw=dw] if sp_sb_sg_c==1 & tdgr>=5 & tdgr<=14 & (wantsnomore==1|femster==1|infert==1), vce(robust)
 
  reg bornkids fg [pw=dw] if sp_sb_sg_c==1 & tdgr>=15 & (wantsnomore==1|femster==1|infert==1), vce(robust)
 


*-------------------
***   TABLE 3    ***, EFFECT OF A FIRST-BORN GIRL ON MODERATE TO SEVERE ANEMIA BY COUNTRY GROUP
*-------------------


	forval i=1/3 {


	
capture reg sevmodanemic fg i.year i.CN [pw=dw] if sp_sb_sg_c_an==`i'  & resp_ht!=. & edu!=. & agefb!=., vce(robust)
outreg2 using "$output_latex\taban1_gr.xls", nolabel ctitle(sevmodanemic, sp_sb_sg_c `i' , +CountryFEs) se bdec(3) rdec(3) append

capture reg sevmodanemic  fg $contr [pw=dw] if sp_sb_sg_c_an==`i' , vce(robust)
outreg2 using "$output_latex\taban1_gr.xls", nolabel ctitle(sevmodanemic, sp_sb_sg_c `i' , +controls) se bdec(3) rdec(3) append

}


*-------------------
***   TABLE 4    ***,  ROBUSTNESS TO ALTERNATIVE CHANNELS
*-------------------
estimates clear
local varlist "finalsay_ownh beat_any refusesex_any domviol food_pc living_pc"


foreach var in `varlist' {
eststo `var':  reg `var' fg $contr  [pw=dw] if sp_sb_sg_c==1 & resp_ht!=. & edu!=. & agefb!=. & sevmodanemic!=.  , vce(robust)
sum `var' if (fg==0 & e(sample)==1) [aw=dw]
estadd scalar ym = r(mean)
}

eststo iron_fp:  reg iron_fp      fg $contr    [pw=dw] if resp_ht!=. & edu!=. & agefb!=. & sevmodanemic!=.  & v201==1 & td<=36, vce(robust)
sum iron_fp if (fg==0 & e(sample)==1) [aw=dw]
estadd scalar ym = r(mean)


gen antevisits_2=1 if num_antenatvisit>=2 & num_antenatvisit!=.
replace antevisits_2=0 if num_antenatvisit<2 & num_antenatvisit!=.
tab antevisits_2,m
label var antevisits_2 "\shortstack{At least 2 \\antenatal visits}"


eststo visit:  reg antevisits_2   fg $contr    [pw=dw] if resp_ht!=. & edu!=. & agefb!=. & sevmodanemic!=.  & v201==1 & td<=36, vce(robust)
sum antevisits_2 if (fg==0 & e(sample)==1) [aw=dw]
estadd scalar ym = r(mean)


esttab finalsay_ownh beat_any refusesex_any domviol iron_fp visit food_pc living_pc using "$output_latex\rob_all_ansample.tex", replace ///
	   label cells(b(star fmt(3)) se(par fmt(3))) sca(fstat) ///
	   collabels(none)  stats(N  r2 ym, label("Obs." " $ R^2 $ " "Control mean") fmt(%12.0fc 3)  )    ///
	   obslast star(* 0.10 ** 0.05 *** .01)   nogap onecell  booktabs ///
	   keep(fg) compress 
		   
		   


*====================================
*
***      APPENDIX      FIGURES    ***
*
*====================================




*-------------------
***   FIGURE A1    ***, Sonpref measures plot by country
*-------------------
use "$data\master_corr_sb.dta", clear
keep if befaft2000==1
 
keep if   wantsnomore==1|femster==1|infert==1

collapse hi_sp_sg_c (mean) srlb_mean=lg (sem) srlb_se = lg  (sd) srlb_sd = lg [aw=dw] , by(CountryName ) 

gen upper= srlb_mean+(1.96* srlb_se)
gen lower= srlb_mean-(1.96* srlb_se)

sort srlb_mean
gen order = _n

	 forval i = 1/44{
     local label = CountryName[`i']
     label def order  `i' "`label'", add
}
label val order order 
 
 
twoway (scatter srlb_mean order  if hi_sp_sg_c==1 ,msymbol(diamond) mcolor(red)    lc(orange*0.5) lp(vshortdash) lw(medthick)) ///
	   (scatter srlb_mean order  if hi_sp_sg_c==0 ,msymbol(circle_hollow) mcolor (green)  lc(orange*0.5) lp(vshortdash) lw(medthick)) || ///
       (rcap upper  lower  order , lstyle(ci)  lc(orange*0.5))   , /// 
	   xtitle("Country") ///
	   ytitle("SRLB") ///
	   title("") ///
	   xlabel(1(1)44,valuelabel angle(45) labs(tiny)  ) ///
	   xscale(r(0 44)titlegap(10)) ///
	   ylabel(.39 (.02) .54)  ///
	   legend(order(1 "High Son Preference as per our measure" 2 "Low Son Preference as per our measure" ) size(vsmall) rows(1) symxsize(*0.5))   ///
	   xline(19.5, lpattern(dash)lcolor(navy))  ///
	   text(.53 5 "Countries w/ SRLB<.485", place(e) size(small)) text(.53 25 "Countries w/ SRLB>.485", place(e) size(small))
graph export  "$output_latex\srlb_bycountry.eps", replace


*-------------------
***   FIGURE A2    ***, COMPOSITION OF THE 4 COUNTRY GROUPS
*-------------------

use "$data\master_corr_sb.dta", clear
keep if befaft2000==1
count
 
label define  sp_sb_sg_c 1 "a) High SonPref-Low MatCare (43%)" 2 "b) Low SonPref-High MatCare (7%)" 3 "c) Low SonPref-Low MatCare (43%)" 4 "d) High SonPref-High MatCare (7%)", replace
label values sp_sb_sg_c sp_sb_sg_c 
tab sp_sb_sg_c 

graph pie, over(Region_WB) by(sp_sb_sg_c,note("") )   

graph export  "$output_latex\pie_women.png", replace


*-------------------
***   FIGURE A3    ***, SHARE OF WOMEN WITH FIRST-BORN GIRL, ROBUSTNESS CHECKS WITH ALTERNATIVE CUT-OFFS
*-------------------
  
*use "$data\master_corr_sb.dta", clear
*keep if befaft2000==1

 
gen hi_sp2_sg_c=sptotal_sg_c>=3 if sptotal_sg_c!=.
label var hi_sp2_sg_c "Son preference indicator (=1 if at least 3 of the 5 SP dummies=1)"
label define  hi_sp2_sg_c 0 "No/Low son preference" 1 "High son preference" 
label values hi_sp2_sg_c hi_sp2_sg_c
 
gen hi_sp3_sg_c=sptotal_sg_c>=4 if sptotal_sg_c!=.
label var hi_sp3_sg_c "Son preference indicator (=1 if at least 4 of the 5 SP dummies=1)"
label define  hi_sp3_sg_c 0 "No/Low son preference" 1 "High son preference" 
label values hi_sp3_sg_c hi_sp3_sg_c
 
gen hi_sp0_sg_c=sptotal_sg_c>=1 if sptotal_sg_c!=.
label var hi_sp0_sg_c "Son preference indicator (=1 if at least 1 of the 5 SP dummies=1)"
label define  hi_sp0_sg_c 0 "No/Low son preference" 1 "High son preference" 
label values hi_sp0_sg_c hi_sp0_sg_c 
 
gen     sp2_sb_sg_c=1 if hi_sp2_sg_c==1 & low_sb_med==1
 
replace sp2_sb_sg_c=2 if hi_sp2_sg_c==0 & low_sb_med==0
 
replace sp2_sb_sg_c=3 if hi_sp2_sg_c==0 & low_sb_med==1
 
replace sp2_sb_sg_c=4 if hi_sp2_sg_c==1 & low_sb_med==0
 
label define  sp_sb_sg_c 1 "a) High SonPref-Low MatCare" 2 "b) Low SonPref-High MatCare" 3 "c) Low SonPref-Low MatCare" 4 "d) High SonPref-High MatCare", replace
label values sp2_sb_sg_c sp_sb_sg_c 
 
 
 
gen     sp0_sb_sg_c=1 if hi_sp0_sg_c==1 & low_sb_med==1
 
replace sp0_sb_sg_c=2 if hi_sp0_sg_c==0 & low_sb_med==0
 
replace sp0_sb_sg_c=3 if hi_sp0_sg_c==0 & low_sb_med==1
 
replace sp0_sb_sg_c=4 if hi_sp0_sg_c==1 & low_sb_med==0
 
label values sp0_sb_sg_c sp_sb_sg_c 
 
 
 
gen     sp3_sb_sg_c=1 if hi_sp3_sg_c==1 & low_sb_med==1
 
replace sp3_sb_sg_c=2 if hi_sp3_sg_c==0 & low_sb_med==0
 
replace sp3_sb_sg_c=3 if hi_sp3_sg_c==0 & low_sb_med==1
 
replace sp3_sb_sg_c=4 if hi_sp3_sg_c==1 & low_sb_med==0
 
label values sp3_sb_sg_c sp_sb_sg_c
 

label values sp_sb_sg_c sp_sb_sg_c 
tab sp_sb_sg_c 



twoway (lpolyci fg tdgr if tdgr<=25  [aw=dw],by(sp0_sb_sg_c,note("")title("Panel A")) ///
		bw(7) clc(red) ciplot(rline) clwidth(thick) acolor(red) alp(shortdash)), ///
      	xtitle("Time since first delivery")   xlabel(0(5)25)  ///
		legend(order(1 "95% CIs" 2 "share with first-born girls") rows(1)) ///
		ytitle("Share with first-born girls") ///
		yline(0.489, lwidth(13) lc(gs15)) ylabel(0.475(0.005)0.49)
graph export  "$output_latex\share_sp0.eps", replace


twoway (lpolyci fg tdgr if tdgr<=25  [aw=dw],by(sp2_sb_sg_c,note("")title("Panel B") ) ///
		bw(7) clc(red) ciplot(rline) clwidth(thick) acolor(red) alp(shortdash)), ///
      	xtitle("Time since first delivery")   xlabel(0(5)25)  legend(order(1 "95% CIs" 2 "share with first-born girls") rows(1)) ///
		ytitle("Share with first-born girls") yline(0.489, lwidth(13) lc(gs15)) ylabel(0.475(0.005)0.49) 
graph export  "$output_latex\share_sp2.eps", replace



twoway (lpolyci fg tdgr if tdgr<=25  [aw=dw],by(sp3_sb_sg_c,note("")title("Panel C")) ///
		bw(7) clc(red) ciplot(rline) clwidth(thick) acolor(red) alp(shortdash)), ///
      	xtitle("Time since first delivery")   xlabel(0(5)25)  legend(order(1 "95% CIs" 2 "share with first-born girls") rows(1)) ///
		ytitle("Share with first-born girls") yline(0.489, lwidth(13.5) lc(gs15)) ylabel(0.475(0.005)0.49)
graph export  "$output_latex\share_sp3.eps", replace


*-------------------
***   FIGURE A4    ***, SHARE OF WOMEN WITH FIRST-BORN GIRL, robustness checks with alternative definitions of son preference and maternal care
*-------------------

gen     splg_sb_c=1 if hisp_lg_c==1 & low_sb_med==1
replace splg_sb_c=2 if hisp_lg_c==0 & low_sb_med==0
replace splg_sb_c=3 if hisp_lg_c==0 & low_sb_med==1
replace splg_sb_c=4 if hisp_lg_c==1 & low_sb_med==0
 
 label define  srlbc 1 "a) Low SRLB-Low MatCare" 2 "b) High SRLB-High MatCare" 3 "c) High SRLB-Low MatCare" 4 "d) Low SRLB-High MatCare", replace
label values splg_sb_c srlbc

label var splg_sb_c "Combined high sp (SRLB) & Skill Birth COUNTRY LEVEL"
tab splg_sb_c
bys splg_sb_c:tab CountryName


twoway (lpolyci fg tdgr if tdgr<=25 [aw=dw],by(splg_sb_c,note("")title("Panel A")) ///
		bw(7) clc(red) ciplot(rline) clwidth(thick) acolor(red) alp(shortdash)), ///
      	xtitle("Time since first delivery")   xlabel(0(5)25)  legend(order(1 "95% CIs" 2 "share with first-born girls") rows(1)) ///
		ytitle("Share with first-born girls") yline(0.489, lwidth(13) lc(gs15)) ylabel(0.475(0.005)0.49)
graph export  "$output_latex\share_lg.eps", replace



use "$dhs\correlates_allctys_inc.dta", clear // Country level data from World Development Indicators database
sort CountryCode year

tab incomegroup,m
gen inc=.
replace inc=1 if incomegroup=="High income"
replace inc=2 if incomegroup=="Low income"
replace inc=3 if incomegroup=="Lower middle income"
replace inc=4 if incomegroup=="Upper middle income"
count if inc==1

label define inc 1 "High income" 2 "Low income" 3 "Lower middle income" 4 "Upper middle income"
label values inc inc
tab inc

* drop high income countries
drop if inc==1
count
*   527,175

keep if year==2005

/*su  hltexp_gdp  //127 ctys

tab CountryName if hltexp_gdp==. & IndicatorName=="Current health expenditure (% of GDP)" //8 ctys
tab CountryName if hltexp_gdp!=. & IndicatorName=="Current health expenditure (% of GDP)" //127 ctys

tab CountryName if prenatalcare==. & IndicatorName=="Pregnant women receiving prenatal care (%)" //99 ctys
tab CountryName if prenatalcare!=. & IndicatorName=="Pregnant women receiving prenatal care (%)" //36 ctys

tab CountryName if nmr==. & IndicatorName=="Mortality rate, neonatal (per 1,000 live births)" //2 ctys
tab CountryName if nmr!=. & IndicatorName=="Mortality rate, neonatal (per 1,000 live births)" //133 ctys

tab CountryName if nurs_midw==. & IndicatorName=="Nurses and midwives (per 1,000 people)" //99 ctys
tab CountryName if nurs_midw!=. & IndicatorName=="Nurses and midwives (per 1,000 people)" //36 ctys

*/


keep if  IndicatorName=="Current health expenditure (% of GDP)"|IndicatorName=="Mortality rate, neonatal (per 1,000 live births)"

su hltexp_gdp nmr,d  //[median value to divide countries for hltexp_gdp==5.227888, median for nmr= 22.8 ]


gen low_hltexp_gdp_med=hltexp_gdp<5.227888 if hltexp_gdp!=.

su low_hltexp_gdp_med
tab low_hltexp_gdp_med ,m
bys low_hltexp_gdp_med: tab CountryName if hltexp_gdp!=.


gen hi_nmr_med=nmr>=22.8 if nmr!=.
su hi_nmr_med
tab hi_nmr_med
bys hi_nmr_med: tab CountryName if hi_nmr_med!=.


//// For two DHS ctys, Tanzania and Zimbabwe, healthexp is missing until 2012.for 2012, median healthexp=5.46, nmr 19.3 and Tanzania & Zimbabwe are high hltexp_gdp in 2012 as per median of 2012. 
replace low_hltexp_gdp_med=0 if CountryName=="Tanzania"|CountryName=="Zimbabwe"

keep low_hltexp_gdp_med hi_nmr_med Code CountryName

ren low_hltexp_gdp_med low_hltexp_gdp_med2005
ren hi_nmr_med hi_nmr_med2005


collapse low_hltexp_gdp_med2005 hi_nmr_med2005, by(Code CountryName)
drop if Code=="."


save "$dhs\hltexp_med_2005", replace


//merge this with individual level data 

use "$data\master_corr_sb.dta", clear
keep if befaft2000==1
 count
 drop _merge
merge m:1 Code using "$dhs\hltexp_med_2005" 
drop if _merge==2
drop _merge

gen     sp_he_sg_c=1 if hi_sp_sg_c==1 & low_hltexp_gdp_med2005==1

replace sp_he_sg_c=2 if hi_sp_sg_c==0 & low_hltexp_gdp_med2005==0

replace sp_he_sg_c=3 if hi_sp_sg_c==0 & low_hltexp_gdp_med2005==1

replace sp_he_sg_c=4 if hi_sp_sg_c==1 & low_hltexp_gdp_med2005==0

bys sp_he_sg_c:tab CountryName 

label define  sp_he_sg_c 1 "a) High SonPref-Low Health exp" 2 "b) Low SonPref-High Health exp" 3 "c) Low SonPref-Low Health exp" 4 "d) High SonPref-High Health exp", replace
label values sp_he_sg_c sp_he_sg_c 
tab sp_he_sg_c 

twoway (lpolyci fg tdgr if tdgr<=25 [aw=dw],by(sp_he_sg_c,note("") title("Panel B")) ///
		bw(7) clc(red) ciplot(rline) clwidth(thick) acolor(red) alp(shortdash)), ///
      	xtitle("Time since first delivery")   xlabel(0(5)25)  legend(order(1 "95% CIs" 2 "share with first-born girls") rows(1)) ///
		ytitle("Share with first-born girls") yline(0.489, lwidth(11) lc(gs15)) ylabel(0.475(0.005)0.49)
graph export  "$output_latex\share_hlthexp.png", replace

gen     sp_nmr_sg_c=1 if hi_sp_sg_c==1 & hi_nmr_med2005==1

replace sp_nmr_sg_c=2 if hi_sp_sg_c==0 & hi_nmr_med2005==0

replace sp_nmr_sg_c=3 if hi_sp_sg_c==0 & hi_nmr_med2005==1

replace sp_nmr_sg_c=4 if hi_sp_sg_c==1 & hi_nmr_med2005==0

bys sp_nmr_sg_c:tab CountryName

label define  sp_nmr_sg_c 1 "a) High SonPref-High NMR" 2 "b) Low SonPref-Low NMR" 3 "c) Low SonPref-High NMR" 4 "d) High SonPref-Low NMR", replace
label values sp_nmr_sg_c sp_nmr_sg_c 
tab sp_nmr_sg_c 


twoway (lpolyci fg tdgr if tdgr<=25 [aw=dw],by(sp_nmr_sg_c,note("")title("Panel C")) ///
		bw(7) clc(red) ciplot(rline) clwidth(thick) acolor(red) alp(shortdash)), ///
      	xtitle("Time since first delivery")   xlabel(0(5)25)  legend(order(1 "95% CIs" 2 "share with first-born girls") rows(1)) ///
		ytitle("Share with first-born girls") yline(0.489, lwidth(12) lc(gs15)) ylabel(0.475(0.005)0.49)
graph export  "$output_latex\share_nmr.png", replace


*-------------------
***   FIGURE A5    ***, SHARE OF WOMEN WITH FIRST-BORN GIRLS IN THE HL GROUP, WITH AND WITHOUT INDIA
*-------------------


use "$data\master_corr_sb.dta", clear
keep if befaft2000==1

 

twoway (lpolyci fg tdgr if tdgr<=25  & sp_sb_sg_c==1 [aw=dw], bw(7) clc(red) ciplot(rline) clwidth(thick) acolor(red) alp(shortdash)) ///
  (lpolyci fg tdgr if tdgr<=25  & sp_sb_sg_c==1 & CountryName!="India" [aw=dw], bw(7) clc(blue)ciplot(rline) clwidth(thick) acolor(blue) alp(shortdash)), ///
		xtitle("Time since first delivery")   xlabel(0(5)25) legend(order(1 "95% CI" 2 "with India" 4 "w/o India") rows(1)) ///
		ytitle("Share with first-born girls",size(small))  title( "")  yline(0.489, lwidth(48) lc(gs15)) ylabel(0.475(0.005)0.485)
graph export  "$output_latex\share_india.png", replace


*-------------------
***   FIGURE A6    ***, SHARE OF WOMEN WITH FIRST-BORN GIRLS FOR THE HL GROUP, INDIVIDUAL-LEVEL HETEROGENEITY
*-------------------

twoway (lpolyci fg tdgr if tdgr<=25 & urban==0 & sp_sb_sg_c==1 [aw=dw], bw(6) clc(red) ciplot(rline) clwidth(thick) acolor(red) alp(shortdash)) ///
       (lpolyci fg tdgr if tdgr<=25 & urban==1 & sp_sb_sg_c==1 [aw=dw], bw(6) clc(blue)ciplot(rline) clwidth(thick) acolor(blue) alp(shortdash)), ///
		xtitle("Time since first delivery")   xlabel(0(5)25) legend(order(1 "95% CI" 2 "rural" 4 "urban") rows(1)) ///
		ytitle("Share with first-born girls",size(small))  title( "")  yline(0.489, lwidth(22) lc(gs15))
graph export  "$output_latex\share_byurbrur.png", replace

twoway (lpolyci fg tdgr if tdgr<=25 & prob_hcare_dist==1 & sp_sb_sg_c==1 [aw=dw], bw(6) clc(red) ciplot(rline) clwidth(thick) acolor(red) alp(shortdash)) ///
       (lpolyci fg tdgr if tdgr<=25 & prob_hcare_dist==0 & sp_sb_sg_c==1 [aw=dw], bw(6) clc(blue)ciplot(rline) clwidth(thick) acolor(blue) alp(shortdash)), ///
		xtitle("Time since first delivery")   xlabel(0(5)25) legend(order(1 "95% CI" 2 "distance a problem" 4 "distance not a problem") rows(1)) ///
		ytitle("Share with first-born girls",size(small))  title( "")  yline(0.489, lwidth(22) lc(gs15))
graph export  "$output_latex\share_bydist.png", replace



*-------------------
***   FIGURE A7    ***, SHARE OF MODERATELY OR SEVERELY ANEMIC WOMEN, BY TIME SINCE THE BIRTH OF THE FIRST, SECOND, AND THIRD GIRL, LL AND HH GROUP
*-------------------
gen fg_0=fg
gen fg_1=fg
gen fg_2=fg
gen fg_3=fg
gen fg_4=fg

gen sg_0=sg
gen sg_1=sg
gen sg_2=sg
gen sg_3=sg
gen sg_4=sg

gen tg_0=tg
gen tg_1=tg
gen tg_2=tg
gen tg_3=tg
gen tg_4=tg

lab var fg_0 "overall"
lab var fg_1 "< 1 year"
lab var fg_2 "1-4 years"
lab var fg_3 "5-14 years"
lab var fg_4 "≥ 15 years"

lab var sg_0 "overall"
lab var sg_1 "< 1 year"
lab var sg_2 "1-4 years"
lab var sg_3 "5-14 years"
lab var sg_4 "≥ 15 years"

lab var tg_0 "overall"
lab var tg_1 "< 1 year"
lab var tg_2 "1-4 years"
lab var tg_3 "5-14 years"
lab var tg_4 "≥ 15 years"

estimates clear



reg sevmodanemic fg_0 $contr [pw=dw] if sp_sb_sg_c==3 , vce(robust)
estimates store fg_0
reg sevmodanemic fg_1 $contr [pw=dw] if sp_sb_sg_c==3 & td<12 , vce(robust)
estimates store fg_1
reg sevmodanemic fg_2 $contr [pw=dw] if sp_sb_sg_c==3 & tdgr>=1 & tdgr<=4, vce(robust)
estimates store fg_2
reg sevmodanemic fg_3 $contr [pw=dw] if sp_sb_sg_c==3 & tdgr>=5 & tdgr<=14 , vce(robust)
estimates store fg_3
reg sevmodanemic fg_4 $contr [pw=dw] if sp_sb_sg_c==3 & tdgr>=15 , vce(robust)
estimates store fg_4

reg sevmodanemic sg_0 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==3 , vce(robust)
estimates store sg_0
reg sevmodanemic sg_1 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==3 & tsd<12 , vce(robust)
estimates store sg_1
reg sevmodanemic sg_2 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==3 & tdgr_s>=1 & tdgr_s<=4, vce(robust)
estimates store sg_2
reg sevmodanemic sg_3 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==3 & tdgr_s>=5 & tdgr_s<=14 , vce(robust)
estimates store sg_3
reg sevmodanemic sg_4 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==3 & tdgr_s>=15 , vce(robust)
estimates store sg_4

reg sevmodanemic tg_0 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==3 , vce(robust)
estimates store tg_0
reg sevmodanemic tg_1 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==3 & ttd<12 , vce(robust)
estimates store tg_1
reg sevmodanemic tg_2 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==3 & tdgr_t>=1 & tdgr_t<=4, vce(robust)
estimates store tg_2
reg sevmodanemic tg_3 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==3 & tdgr_t>=5 & tdgr_t<=14 , vce(robust)
estimates store tg_3
reg sevmodanemic tg_4 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==3 & tdgr_t>=15 , vce(robust)
estimates store tg_4



coefplot (fg_0, mcolor(black) ciopts(lcolor(black black) )) (fg_1 fg_2 fg_3 fg_4, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(sg_0, mcolor(black) ciopts(lcolor(black black))) (sg_1 sg_2 sg_3 sg_4, mcolor(gs8) ciopts(lcolor(gs8 gs8))) ///
	(tg_0, mcolor(black) ciopts(lcolor(black black)))  (tg_1 tg_2 tg_3 tg_4, mcolor(gs8) ciopts(lcolor(gs8 gs8))), vertical legend(off) ///
	keep(fg_0 fg_1 fg_2 fg_3 fg_4 sg_0 sg_1 sg_2 sg_3 sg_4 tg_0 tg_1 tg_2 tg_3 tg_4) xlabel(,alternate) ///
	yline(0)  coeflabels(, wrap(14) labsize(*.6)) levels(95 90) ylabel(-0.05(0.01)0.04) xtitle(" " "length of time after the birth of first, second, and third girl", size(small)) ///
	ytitle("probability of being moderately or severely anemic (girl-boy)" " ", size(small))  ///
	groups(fg_0 fg_1 fg_2 fg_3 fg_4="first girl" sg_0 sg_1 sg_2 sg_3 sg_4="second girl|G"  tg_0 tg_1 tg_2 tg_3 tg_4="third girl|GG" ,labsize(small) ) 
graph export  "$output_latex\sevmodanemia_gr3_td.png", replace


drop fg_* sg_* tg_*

gen fg_0=fg
gen fg_1=fg
gen fg_2=fg
gen fg_3=fg
gen fg_4=fg

gen sg_0=sg
gen sg_1=sg
gen sg_2=sg
gen sg_3=sg
gen sg_4=sg

gen tg_0=tg
gen tg_1=tg
gen tg_2=tg
gen tg_3=tg
gen tg_4=tg

lab var fg_0 "overall"
lab var fg_1 "< 1 year"
lab var fg_2 "1-4 years"
lab var fg_3 "5-14 years"
lab var fg_4 "≥ 15 years"

lab var sg_0 "overall"
lab var sg_1 "< 1 year"
lab var sg_2 "1-4 years"
lab var sg_3 "5-14 years"
lab var sg_4 "≥ 15 years"

lab var tg_0 "overall"
lab var tg_1 "< 1 year"
lab var tg_2 "1-4 years"
lab var tg_3 "5-14 years"
lab var tg_4 "≥ 15 years"

estimates clear



reg sevmodanemic fg_0 $contr [pw=dw] if sp_sb_sg_c==4 , vce(robust)
estimates store fg_0
reg sevmodanemic fg_1 $contr [pw=dw] if sp_sb_sg_c==4 & td<12 , vce(robust)
estimates store fg_1
reg sevmodanemic fg_2 $contr [pw=dw] if sp_sb_sg_c==4 & tdgr>=1 & tdgr<=4, vce(robust)
estimates store fg_2
reg sevmodanemic fg_3 $contr [pw=dw] if sp_sb_sg_c==4 & tdgr>=5 & tdgr<=14 , vce(robust)
estimates store fg_3
reg sevmodanemic fg_4 $contr [pw=dw] if sp_sb_sg_c==4 & tdgr>=15 , vce(robust)
estimates store fg_4

reg sevmodanemic sg_0 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==4 , vce(robust)
estimates store sg_0
reg sevmodanemic sg_1 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==4 & tsd<12 , vce(robust)
estimates store sg_1
reg sevmodanemic sg_2 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==4 & tdgr_s>=1 & tdgr_s<=4, vce(robust)
estimates store sg_2
reg sevmodanemic sg_3 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==4 & tdgr_s>=5 & tdgr_s<=14 , vce(robust)
estimates store sg_3
reg sevmodanemic sg_4 $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==4 & tdgr_s>=15 , vce(robust)
estimates store sg_4

reg sevmodanemic tg_0 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==4 , vce(robust)
estimates store tg_0
reg sevmodanemic tg_1 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==4 & ttd<12 , vce(robust)
estimates store tg_1
reg sevmodanemic tg_2 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==4 & tdgr_t>=1 & tdgr_t<=4, vce(robust)
estimates store tg_2
reg sevmodanemic tg_3 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==4 & tdgr_t>=5 & tdgr_t<=14 , vce(robust)
estimates store tg_3
reg sevmodanemic tg_4 $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==4 & tdgr_t>=15 , vce(robust)
estimates store tg_4



coefplot (fg_0, mcolor(black) ciopts(lcolor(black black) )) (fg_1 fg_2 fg_3 fg_4, mcolor(gs8) ciopts(lcolor(gs8 gs8))) /// 
	(sg_0, mcolor(black) ciopts(lcolor(black black))) (sg_1 sg_2 sg_3 sg_4, mcolor(gs8) ciopts(lcolor(gs8 gs8))) ///
	(tg_0, mcolor(black) ciopts(lcolor(black black)))  (tg_1 tg_2 tg_3 tg_4, mcolor(gs8) ciopts(lcolor(gs8 gs8))), vertical legend(off) ///
	keep(fg_0 fg_1 fg_2 fg_3 fg_4 sg_0 sg_1 sg_2 sg_3 sg_4 tg_0 tg_1 tg_2 tg_3 tg_4) xlabel(,alternate) ///
	yline(0)  coeflabels(, wrap(14) labsize(*.6)) levels(95 90) ylabel(-0.1(0.02)0.04) xtitle(" " "length of time after the birth of first, second, and third girl", size(small)) ///
	ytitle("probability of being moderately or severely anemic (girl-boy)" " ", size(small))  ///
	groups(fg_0 fg_1 fg_2 fg_3 fg_4="first girl" sg_0 sg_1 sg_2 sg_3 sg_4="second girl|G"  tg_0 tg_1 tg_2 tg_3 tg_4="third girl|GG" ,labsize(small) ) 
graph export  "$output_latex\sevmodanemia_gr4_td.png", replace

drop fg_* sg_* tg_*

*-------------------
***   FIGURE A8    ***, OVER TIME PATTERNS IN SON PREFERENCE DIMENSIONS AND ANEMIA, LH, LL, AND HH GROUPS
*-------------------
*See code above for Figure 8


*-------------------
***   FIGURE A9    ***, OVER TIME PATTERNS IN SON PREFERENCE DIMENSIONS AND ANEMIA FOR THE HL GROUP, WITHOUT INDIA
*-------------------

gen spacing1_2_div=spacing1_2/10

gen fg1=fg
gen fg2=fg
gen fg3=fg
gen fg4=fg
gen fg5=fg
gen fg6=fg

gen fg1_ed=fg
gen fg2_ed=fg
gen fg3_ed=fg
gen fg4_ed=fg
gen fg5_ed=fg

gen fg1_noed=fg
gen fg2_noed=fg
gen fg3_noed=fg
gen fg4_noed=fg
gen fg5_noed=fg

estimates clear

reg bornkids i.fg1##c.year $contr_noht if sp_sb_sg_c==1  & (wantsnomore==1|femster==1|infert==1) & CountryName!="India" [pw=dw], r	
estimates store bornkids
reg wantsmore i.fg2##c.year $contr_noht  if sp_sb_sg_c==1  & CountryName!="India"    [pw=dw], r	
estimates store wantsmore
reg sg i.fg3##c.year $contr_noht  if v201>=2 & sp_sb_sg_c==1   & CountryName!="India"   [pw=dw], r	
estimates store sg
reg contrac i.fg4##c.year  $contr_noht  if sp_sb_sg_c==1  & CountryName!="India"   [pw=dw], r	
estimates store contrac
reg spacing1_2_div i.fg5##c.year  $contr_noht  if  v201>=2 & sp_sb_sg_c==1 & CountryName!="India"   [pw=dw], r	
estimates store spacing1_2
reg sevmodanemic i.fg6##c.year resp_ht $contr  if  sp_sb_sg_c==1  & CountryName!="India" [pw=dw], r	
estimates store sevmodanemic

reg bornkids i.fg1##c.year $contr_noht if sp_sb_sg_c==1  & (wantsnomore==1|femster==1|infert==1) & edu==0  & CountryName!="India"  [pw=dw], r	
estimates store bornkids_noed
reg wantsmore i.fg2##c.year $contr_noht  if sp_sb_sg_c==1  & edu==0 & CountryName!="India"   [pw=dw], r	
estimates store wantsmore_noed
reg sg i.fg3##c.year $contr_noht  if v201>=2 & sp_sb_sg_c==1  & edu==0 & CountryName!="India"    [pw=dw], r	
estimates store sg_noed
reg contrac i.fg4##c.year  $contr_noht  if sp_sb_sg_c==1  & edu==0   & CountryName!="India"  [pw=dw], r	
estimates store contrac_noed
reg spacing1_2_div i.fg5##c.year  $contr_noht  if  v201>=2 & sp_sb_sg_c==1  & edu==0  & CountryName!="India"   [pw=dw], r	
estimates store spacing1_2_noed
reg sevmodanemic i.fg6##c.year  $contr resp_ht if  sp_sb_sg_c==1 & edu==0  & CountryName!="India"  [pw=dw], r	
estimates store sevmodanemic_noed


reg bornkids i.fg1##c.year $contr_noht if sp_sb_sg_c==1  & (wantsnomore==1|femster==1|infert==1) & edu==1  & CountryName!="India"  [pw=dw], r	
estimates store bornkids_ed
reg wantsmore i.fg2##c.year $contr_noht  if sp_sb_sg_c==1  & edu==1  & CountryName!="India"   [pw=dw], r	
estimates store wantsmore_ed
reg sg i.fg3##c.year $contr_noht  if v201>=2 & sp_sb_sg_c==1  & edu==1    & CountryName!="India"  [pw=dw], r	
estimates store sg_ed
reg contrac i.fg4##c.year  $contr_noht  if sp_sb_sg_c==1  & edu==1  & CountryName!="India"  [pw=dw], r	
estimates store contrac_ed
reg spacing1_2_div i.fg5##c.year  $contr_noht  if  v201>=2 & sp_sb_sg_c==1  & edu==1  & CountryName!="India"    [pw=dw], r	
estimates store spacing1_2_ed
reg sevmodanemic i.fg6##c.year  $contr resp_ht if  sp_sb_sg_c==1 & edu==1  & CountryName!="India"   [pw=dw], r	
estimates store sevmodanemic_ed



coefplot 	(sevmodanemic bornkids wantsmore sg contrac spacing1_2 , label(full sample) msymbol(O) levels(95 90)) ///
			(sevmodanemic_noed bornkids_noed wantsmore_noed sg_noed contrac_noed spacing1_2_noed , label(eduyrs=0) msymbol(S) levels(95 90)) ///
			(sevmodanemic_ed bornkids_ed wantsmore_ed sg_ed contrac_ed spacing1_2_ed , label(eduyrs>0) msymbol(D) levels(95 90)), ///
			legend(rows(1) pos(6)) xline(0) ///
			keep(1.fg1#c.year 1.fg1_ed#c.year 1.fg1_noed#c.year  1.fg2#c.year  1.fg2_ed#c.year  1.fg2_noed#c.year 1.fg3#c.year 1.fg3_ed#c.year  ///
			1.fg3_noed#c.year  1.fg4#c.year  1.fg4_ed#c.year   1.fg4_noed#c.year 1.fg5#c.year  1.fg5_ed#c.year  1.fg5_noed#c.year ///
			1.fg6#c.year  1.fg6_ed#c.year   1.fg6_noed#c.year  )  ///
			coeflabels(1.fg1#c.year="# children ever born" 1.fg2#c.year="wants more children" ///
			1.fg3#c.year="second-born girl" 1.fg4#c.year="using contraception" ///
			1.fg5#c.year="spacing bw 1st and 2nd child" 1.fg6#c.year="moderately or severely anemic", wrap(20) labsize(*.7)) ///
			ytitle("coefficient on (first-born*year)" " " ,size(small))
graph export  "$output_latex\overtime_gr1_noindia.png", replace
		
		
*-------------------
***   FIGURE A10    ***, OVER TIME PATTERNS IN SON PREFERENCE DIMENSIONS AND ANEMIA FOR THE HL GROUP, RESTRICTING TO COUNTRIES THAT HAVE A SURVEY IN 90S, 2000S, AND 2010s 
*-------------------

estimates clear

reg bornkids i.fg1##c.year $contr_noht if sp_sb_sg_c==1  & (wantsnomore==1|femster==1|infert==1) & yr3_all==1 [pw=dw], r 
estimates store bornkids
reg wantsmore i.fg2##c.year $contr_noht  if sp_sb_sg_c==1 & yr3_all==1    [pw=dw], r 
estimates store wantsmore
reg sg i.fg3##c.year $contr_noht  if v201>=2 & sp_sb_sg_c==1   & yr3_all==1    [pw=dw], r 
estimates store sg
reg contrac i.fg4##c.year  $contr_noht  if sp_sb_sg_c==1  & yr3_all==1   [pw=dw], r 
estimates store contrac
reg spacing1_2_div i.fg5##c.year  $contr_noht  if  v201>=2 & sp_sb_sg_c==1 & yr3_all==1   [pw=dw], r 
estimates store spacing1_2
reg sevmodanemic i.fg6##c.year resp_ht $contr  if  sp_sb_sg_c==1  & yr3_all_an==1  [pw=dw], r 
estimates store sevmodanemic

reg bornkids i.fg1##c.year $contr_noht if sp_sb_sg_c==1  & (wantsnomore==1|femster==1|infert==1) & edu==0  & yr3_all==1  [pw=dw], r 
estimates store bornkids_noed
reg wantsmore i.fg2##c.year $contr_noht  if sp_sb_sg_c==1  & edu==0 & yr3_all==1    [pw=dw], r 
estimates store wantsmore_noed
reg sg i.fg3##c.year $contr_noht  if v201>=2 & sp_sb_sg_c==1  & edu==0 & yr3_all==1     [pw=dw], r 
estimates store sg_noed
reg contrac i.fg4##c.year  $contr_noht  if sp_sb_sg_c==1  & edu==0   & yr3_all==1   [pw=dw], r 
estimates store contrac_noed
reg spacing1_2_div i.fg5##c.year  $contr_noht  if  v201>=2 & sp_sb_sg_c==1  & edu==0  & yr3_all==1  [pw=dw], r 
estimates store spacing1_2_noed
reg sevmodanemic i.fg6##c.year  $contr resp_ht if  sp_sb_sg_c==1 & edu==0 & yr3_all_an==1  [pw=dw], r 
estimates store sevmodanemic_noed

reg bornkids i.fg1##c.year $contr_noht if sp_sb_sg_c==1  & (wantsnomore==1|femster==1|infert==1) & edu==1  & yr3_all==1  [pw=dw], r 
estimates store bornkids_ed
reg wantsmore i.fg2##c.year $contr_noht  if sp_sb_sg_c==1  & edu==1  & yr3_all==1   [pw=dw], r 
estimates store wantsmore_ed
reg sg i.fg3##c.year $contr_noht  if v201>=2 & sp_sb_sg_c==1  & edu==1    & yr3_all==1 [pw=dw], r 
estimates store sg_ed
reg contrac i.fg4##c.year  $contr_noht  if sp_sb_sg_c==1  & edu==1 & yr3_all==1   [pw=dw], r 
estimates store contrac_ed
reg spacing1_2_div i.fg5##c.year  $contr_noht  if  v201>=2 & sp_sb_sg_c==1  & edu==1  & yr3_all==1    [pw=dw], r 
estimates store spacing1_2_ed
reg sevmodanemic i.fg6##c.year  $contr resp_ht if  sp_sb_sg_c==1 & edu==1  & yr3_all_an==1   [pw=dw], r 
estimates store sevmodanemic_ed

coefplot (bornkids wantsmore sg contrac spacing1_2 sevmodanemic, label(full sample) msymbol(O) levels(95 90)) ///
		 (bornkids_noed wantsmore_noed sg_noed contrac_noed spacing1_2_noed sevmodanemic_noed, label(eduyrs=0) msymbol(S) levels(95 90)) ///
		 (bornkids_ed wantsmore_ed sg_ed contrac_ed spacing1_2_ed sevmodanemic_ed, label(eduyrs>0) msymbol(D) levels(95 90)), ///
		 legend(rows(1)pos(6)) xline(0) ///
		 keep(1.fg1#c.year 1.fg1_ed#c.year 1.fg1_noed#c.year  1.fg2#c.year  1.fg2_ed#c.year   1.fg2_noed#c.year ///
		 1.fg3#c.year 1.fg3_ed#c.year   1.fg3_noed#c.year  1.fg4#c.year  1.fg4_ed#c.year   1.fg4_noed#c.year 1.fg5#c.year ///
		 1.fg5_ed#c.year   1.fg5_noed#c.year  1.fg6#c.year  1.fg6_ed#c.year   1.fg6_noed#c.year  )  ///
		coeflabels(1.fg1#c.year="# children ever born" 1.fg2#c.year="wants more children" 1.fg3#c.year="second-born girl" ///
		1.fg4#c.year="using contraception" ///
		1.fg5#c.year="spacing bw 1st and 2nd child" 1.fg6#c.year="moderately or severely anemic", wrap(20) labsize(*.7)) ///
		ytitle("coefficient on (first-born*year)" " " ,size(small))

graph export  "$output_latex\overtime_gr1_yr3_all.png", replace




*-------------------
***   FIGURE A11    ***, OVER TIME PATTERNS IN SON PREFERENCE DIMENSIONS AND ANEMIA CONTROLLING FOR HEIGHT, BY THE 4 COUNTRY GROUPS.
*-------------------

estimates clear

		forval i=1/4 {

estimates clear

reg bornkids i.fg1##c.year $contr if sp_sb_sg_c==`i'  & (wantsnomore==1|femster==1|infert==1) [pw=dw], r	
estimates store bornkids
reg wantsmore i.fg2##c.year $contr  if sp_sb_sg_c==`i'    [pw=dw], r	
estimates store wantsmore
reg sg i.fg3##c.year $contr  if v201>=2 & sp_sb_sg_c==`i'    [pw=dw], r	
estimates store sg
reg contrac i.fg4##c.year  $contr  if sp_sb_sg_c==`i'   [pw=dw], r	
estimates store contr_htac
reg spacing1_2_div i.fg5##c.year  $contr  if  v201>=2 & sp_sb_sg_c==`i'  [pw=dw], r	
estimates store spacing1_2
reg sevmodanemic i.fg6##c.year  $contr  if  sp_sb_sg_c==`i' [pw=dw], r	
estimates store sevmodanemic

reg bornkids i.fg1##c.year $contr if sp_sb_sg_c==`i'  & (wantsnomore==1|femster==1|infert==1) & edu==0  [pw=dw], r	
estimates store bornkids_noed
reg wantsmore i.fg2##c.year $contr  if sp_sb_sg_c==`i'  & edu==0  [pw=dw], r	
estimates store wantsmore_noed
reg sg i.fg3##c.year $contr  if v201>=2 & sp_sb_sg_c==`i'  & edu==0   [pw=dw], r	
estimates store sg_noed
reg contrac i.fg4##c.year  $contr  if sp_sb_sg_c==`i'  & edu==0   [pw=dw], r	
estimates store contr_htac_noed
reg spacing1_2_div i.fg5##c.year  $contr  if  v201>=2 & sp_sb_sg_c==`i'  & edu==0   [pw=dw], r	
estimates store spacing1_2_noed
reg sevmodanemic i.fg6##c.year  $contr if  sp_sb_sg_c==`i' & edu==0  [pw=dw], r	
estimates store sevmodanemic_noed


reg bornkids i.fg1##c.year $contr if sp_sb_sg_c==`i'  & (wantsnomore==1|femster==1|infert==1) & edu==1  [pw=dw], r	
estimates store bornkids_ed
reg wantsmore i.fg2##c.year $contr  if sp_sb_sg_c==`i'  & edu==1   [pw=dw], r	
estimates store wantsmore_ed
reg sg i.fg3##c.year $contr  if v201>=2 & sp_sb_sg_c==`i'  & edu==1    [pw=dw], r	
estimates store sg_ed
reg contrac i.fg4##c.year  $contr  if sp_sb_sg_c==`i'  & edu==1 [pw=dw], r	
estimates store contr_htac_ed
reg spacing1_2_div i.fg5##c.year  $contr  if  v201>=2 & sp_sb_sg_c==`i'  & edu==1    [pw=dw], r	
estimates store spacing1_2_ed
reg sevmodanemic i.fg6##c.year  $contr if  sp_sb_sg_c==`i' & edu==1   [pw=dw], r	
estimates store sevmodanemic_ed



coefplot 	(sevmodanemic bornkids wantsmore sg contr_htac spacing1_2 , label(full sample) msymbol(O) levels(95 90)) ///
			(sevmodanemic_noed bornkids_noed wantsmore_noed sg_noed contr_htac_noed spacing1_2_noed , label(eduyrs=0) msymbol(S) levels(95 90)) ///
			(sevmodanemic_ed bornkids_ed wantsmore_ed sg_ed contr_htac_ed spacing1_2_ed , label(eduyrs>0) msymbol(D) levels(95 90)), legend(rows(1) pos(6)) xline(0) ///
			keep(1.fg1#c.year 1.fg1_ed#c.year 1.fg1_noed#c.year  1.fg2#c.year  1.fg2_ed#c.year   1.fg2_noed#c.year 1.fg3#c.year 1.fg3_ed#c.year   1.fg3_noed#c.year  1.fg4#c.year  1.fg4_ed#c.year   1.fg4_noed#c.year 1.fg5#c.year  1.fg5_ed#c.year   1.fg5_noed#c.year  1.fg6#c.year  1.fg6_ed#c.year   1.fg6_noed#c.year  )  ///
			coeflabels(1.fg1#c.year="# children ever born" 1.fg2#c.year="wants more children" 1.fg3#c.year="second-born girl" 1.fg4#c.year="using contraception" ///
			1.fg5#c.year="spacing bw 1st and 2nd child" 1.fg6#c.year="moderately or severely anemic", wrap(20) labsize(*.7)) ///
			ytitle("coefficient on (first-born*year)" " " ,size(small))
			
graph export  "$output_latex\overtime_gr`i'_ht.png", replace

		}
		
		
		
*-------------------
***   FIGURE A12    ***, PREDICTED FERTILITY OUTCOMES OVER TIME FOR THE HL GROUP
*-------------------
*=================
*** N KIDS ***
*=================
reg bornkids i.fg##c.year $contr_noht_noyr  if sp_sb_sg_c==1  & (wantsnomore==1|femster==1|infert==1)  [pw=dw], r 

margins i.fg, at(year =(1990(5)2020))
marginsplot, ytitle("Linear prediction") plot1opts(lpattern("--")) ///
xtitle("year of the survey") title("Predicted # children born") 
graph export  "$output_latex\int_kids_1.png", replace

margins, dydx(fg) at(year=(1990(5)2020))
marginsplot, ytitle("Linear prediction")   ///
xtitle("year of the survey") title("Average marginal effect, first-girl - first-boy") 
graph export  "$output_latex\int_kids_2.png", replace
*=================
*** wantsmore ***
*=================

reg wantsmore i.fg##c.year $contr_noht_noyr if sp_sb_sg_c==1  [pw=dw], r 

margins i.fg, at(year=(1990(5)2020))
marginsplot, ytitle("Linear prediction") plot1opts(lpattern("--")) ///
xtitle("year of the survey") title("Predicted probability to desire more children") 
graph export  "$output_latex\int_wm_1.png", replace

margins, dydx(fg) at(year=(1990(5)2020))
marginsplot, ytitle("Linear prediction")   ///
xtitle("year of the survey") title("Average marginal effect, first-girl - first-boy") 
graph export  "$output_latex\int_wm_2.png", replace

*=================
*** sg ***
*=================
reg sg i.fg##c.year $contr_noht_noyr if sp_sb_sg_c==1 &v201>=2 [pw=dw], r 
margins 1.fg, at(year=(1990(5)2020))
marginsplot, ytitle("Linear prediction")  legend(order ( 1 "first-born girl")) ///
xtitle("year of the survey") title("Predicted share of women with a second girl after a first girl") 
graph export  "$output_latex\int_sg.png", replace

*=================
*** contrac ***
*=================
reg contrac i.fg##c.year $contr_noht_noyr if sp_sb_sg_c==1 [pw=dw], r 

margins i.fg, at(year=(1990(5)2020))
marginsplot, ytitle("Linear prediction")  ///
xtitle("year of the survey") title("Predicted probability of using contraception") plot1opts(lpattern("--")) 
graph export  "$output_latex\int_con_1.png", replace

margins, dydx(fg) at(year=(1990(5)2020))
marginsplot, ytitle("Linear prediction")   ///
xtitle("year of the survey") title("Average marginal effect, first-girl - first-boy") 
graph export  "$output_latex\int_con_2.png", replace


*-------------------
***   FIGURE A13    ***,PREDICTION  OVER TIME FOR THE HL GROUP, RESTRICTING TO COUNTRIES THAT HAVE A SURVEY IN 90S, 2000S, AND 2010S (I.E., THE SAME COMPOSITION FOR THE THREE DECADES)
*-------------------

*=================
*** N KIDS ***
*=================
reg bornkids i.fg##i.yr3 $contr_noht_noyr  if sp_sb_sg_c==1  & yr3_all==1 & (wantsnomore==1|femster==1|infert==1)  [pw=dw], r 

margins i.fg,  at(yr3=(1(1)3))
marginsplot, ytitle("Linear prediction") plot1opts(lpattern("--")) ///
xtitle("year of the survey") title("Predicted # children born") 
graph export  "$output_latex\int_kids_3.png", replace

margins, dydx(fg)  at(yr3=(1(1)3))
marginsplot, ytitle("Linear prediction")   ///
xtitle("year of the survey") title("Average marginal effect, first-girl - first-boy") 
graph export  "$output_latex\int_kids_4.png", replace
*=================
*** wantsmore ***
*=================

reg wantsmore i.fg##i.yr3 $contr_noht_noyr if sp_sb_sg_c==1 & yr3_all==1  [pw=dw], r 

margins i.fg,  at(yr3=(1(1)3))
marginsplot, ytitle("Linear prediction") plot1opts(lpattern("--")) ///
xtitle("year of the survey") title("Predicted probability to desire more children") 
graph export  "$output_latex\int_wm_3.png", replace

margins, dydx(fg)  at(yr3=(1(1)3))
marginsplot, ytitle("Linear prediction")   ///
xtitle("year of the survey") title("Average marginal effect, first-girl - first-boy") 
graph export  "$output_latex\int_wm_4.png", replace

*=================
*** sg ***
*=================
reg sg i.fg##i.yr3 $contr_noht_noyr if sp_sb_sg_c==1 & v201>=2 & yr3_all==1 [pw=dw], r 
margins 1.fg,  at(yr3=(1(1)3))
marginsplot, ytitle("Linear prediction")  legend(order ( 1 "first-born girl")) ///
xtitle("year of the survey") title("Predicted share of women with a second girl after a first girl") 
graph export  "$output_latex\int_sg1.png", replace

*=================
*** contrac ***
*=================

reg contrac i.fg##i.yr3 $contr_noht_noyr if sp_sb_sg_c==1 & yr3_all==1 [pw=dw], r 

margins i.fg, at(yr3=(1(1)3))
marginsplot, ytitle("Linear prediction")  ///
xtitle("year of the survey") title("Predicted probability of using contraception") 
graph export  "$output_latex\int_con_3.png", replace

margins, dydx(fg) at(yr3=(1(1)3))
marginsplot, ytitle("Linear prediction")   ///
xtitle("year of the survey") title("Average marginal effect, first-girl - first-boy") 
graph export  "$output_latex\int_con_4.png", replace





*====================================
*
***      APPENDIX      TABLES    ***
*
*====================================
use "$data\master_corr_sb.dta", clear
keep if befaft2000==1
 count
 * 2,482,968
 
 
*-------------------
***   TABLE A2    ***, SUMMARY STATISTICS BY THE SEX OF THE FIRST-BORN CHILD, FULL SAMPLE
*-------------------
foreach var of varlist edu eduyrs urban age agefb  termpreg sg  contrac wantsmore spacing1_2  ///
	 anemic sevmodanemic  resp_ht bmi {
	
capture reg `var' fg [pw=dw], vce(robust)
outreg2 using "$output_latex\SS_all.xls", nolabel ctitle(`var',, all) se bdec(3) rdec(3) append
}
reg bornkids fg [pw=dw] if  (wantsnomore==1|femster==1|infert==1), vce(robust)


*-------------------
***   TABLE A3    ***,  ROBUSTNESS CHECKS FOR THE TREND IN THE SHARE OF WOMEN WITH FIRST BORN GIRL  
*-------------------
 
 gen india=CountryName=="India"
 label var india "India"
 label var tdgr "years after first delivery"
  
 
estimates clear

eststo slope1: reg fg c.tdgr##i.sp_sb_sg_c                  [pw=dw], r
qui estadd local samp "Full Sample"

eststo  slope2: reg fg c.tdgr##i.india      if sp_sb_sg_c==1[pw=dw], r
qui estadd local samp "High SP-Low MC countries"

	
esttab  slope1 slope2  using "$output_latex\slope_rob.tex", replace  ///
			label cells(b(star fmt(4)) se(par fmt(4)))  ///
			collabels(none) nodepvar nomtitles ///
			stats(N r2, fmt(%12.0fc 4) ///
			label("Observations" " $ R^2 $ " "Sample" ))  	///	 
			obslast star(* 0.10 ** 0.05 *** .01) drop( 0.india  0.india#c.tdgr 1.sp_sb_sg_c#c.tdgr  1.sp_sb_sg_c) booktabs ///
			mgroups( "Full Sample" "High SP-Low MC countries", pattern(1 1   ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
 
 
*-------------------
***   TABLE A4    ***,  ROBUSTNESS OF ANEMIA RESULTS TO SAMPLE COMPOSITION (DEP. VAR.: MODERATE TO SEVERE ANEMIA)
*-------------------
tab sp_sb_sg_c
gen sp_sb_sg_c_an=.
replace sp_sb_sg_c_an=1 if sp_sb_sg_c==1
replace sp_sb_sg_c_an=2 if sp_sb_sg_c==3
replace sp_sb_sg_c_an=3 if sp_sb_sg_c==4

label define  sp_sb_sg_c_an 1 "High SonPref-Low MatCare" 2 "Low SonPref-Low MatCare" 3 "High SonPref-High MatCare", replace
label values sp_sb_sg_c_an sp_sb_sg_c_an
tab sp_sb_sg_c_an



estimates clear
eststo :  reg sevmodanemic i.fg##i.sp_sb_sg_c_an $contr [pw=dw] if resp_ht!=. & edu!=. & agefb!=. , vce(robust)
estimates restore x0
qui estadd local samp "Full sample"
qui estadd local contr "Y"

eststo : reg sevmodanemic i.fg##i.india  $contr [pw=dw]     if (sp_sb_sg_c==1)   & resp_ht!=. & edu!=. & agefb!=., vce(robust)
estimates restore x4
qui estadd local samp "High SP-Low MC"
qui estadd local contr "Y"
 
	
 esttab     using "$output_latex\an_rob.tex", replace   ///
			label cells(b(star fmt(3)) se(par fmt(3)))  ///
			collabels(none) nodepvar nomtitles ///
			stats(N r2  , fmt(%12.0fc 2) ///
			label("Observations" " $ R^2 $ "  "Controls")) obslast star(* 0.10 ** 0.05 *** .01) 	///	 
			keep(1.fg 1.india  1.fg#2.sp_sb_sg_c_an 1.fg#3.sp_sb_sg_c_an 1.fg#1.india age agesq ///
			agefb urban eduyrs resp_ht _cons 2.sp_sb_sg_c_an 3.sp_sb_sg_c_an) ///
			order( 1.fg 2.sp_sb_sg_c_an 3.sp_sb_sg_c_an 1.fg#2.sp_sb_sg_c_an 1.fg#3.sp_sb_sg_c_an  ///
			1.india  1.fg#1.india age agesq agefb urban eduyrs resp_ht _cons) booktabs   
			
			
			
*-------------------
***   TABLE A5    ***,  ROBUSTNESS OF ANEMIA RESULTS USING SRLB TO DEFINE HIGH SP
*-------------------
 
* groupings at the country level using SRLB. 
gen     splg_sb_c=1 if hisp_lg_c==1 & low_sb_med==1
replace splg_sb_c=2 if hisp_lg_c==0 & low_sb_med==0
replace splg_sb_c=3 if hisp_lg_c==0 & low_sb_med==1
replace splg_sb_c=4 if hisp_lg_c==1 & low_sb_med==0
 
 label define  srlbc 1 "a) Low SRLB-Low MatCare" 2 "b) High SRLB-High MatCare" 3 "c) High SRLB-Low MatCare" 4 "d) Low SRLB-High MatCare", replace
label values splg_sb_c srlbc

label var splg_sb_c "Combined high sp (SRLB) & Skill Birth COUNTRY LEVEL"
tab splg_sb_c
bys splg_sb_c:tab CountryName


estimates clear
foreach var of varlist  sevmodanemic {
	
capture reg `var' fg i.year i.CN  if splg_sb_c==1  & resp_ht!=. & edu!=. & agefb!=. [pw=dw], vce(robust)
outreg2 using "$output_latex\taban1_gr_splg.xls", nolabel ctitle(`var', splg_sb_c `i' , +CountryFEs) se bdec(3) rdec(3) append

capture reg `var' fg $contr   if splg_sb_c==1 [pw=dw] , vce(robust)
outreg2 using "$output_latex\taban1_gr_splg.xls", nolabel ctitle(`var', splg_sb_c `i' , +controls) se bdec(3) rdec(3) append
}

	forval i=3/4 {

	foreach var of varlist sevmodanemic {
	
capture reg `var' fg i.year i.CN  if splg_sb_c==`i'  & resp_ht!=. & edu!=. & agefb!=. [pw=dw], vce(robust)
outreg2 using "$output_latex\taban1_gr_splg.xls", nolabel ctitle(`var', splg_sb_c `i' , +CountryFEs) se bdec(3) rdec(3) append

capture reg `var' fg $contr   if splg_sb_c==`i' [pw=dw] , vce(robust)
outreg2 using "$output_latex\taban1_gr_splg.xls", nolabel ctitle(`var', splg_sb_c `i' , +controls) se bdec(3) rdec(3) append

}
}


*--------------------------------*
***   TABLE A6 ***  , FEMALE BIRTHS AND MODERATE/SEVERE ANEMIA IN THE HL GROUP, BY TIME SINCE FIRST BIRTH
*--------------------------------*

 
 estimates clear
 
 eststo fg1: reg sevmodanemic fg $contr [pw=dw] if sp_sb_sg_c==1 , vce(robust)
 sum sevmodanemic if (fg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 

 eststo fg2: reg sevmodanemic fg $contr [pw=dw] if sp_sb_sg_c==1 & td<12 , vce(robust)
 sum sevmodanemic if (fg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo fg3: reg sevmodanemic fg $contr [pw=dw] if sp_sb_sg_c==1 & tdgr>=1 & tdgr<=4, vce(robust)
 sum sevmodanemic if (fg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo fg4: reg sevmodanemic fg $contr [pw=dw] if sp_sb_sg_c==1 & tdgr>=5 & tdgr<=14 , vce(robust)
 sum sevmodanemic if (fg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo fg5: reg sevmodanemic fg $contr [pw=dw] if sp_sb_sg_c==1 & tdgr>=15 , vce(robust)
 sum sevmodanemic if (fg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 

eststo sg1: reg sevmodanemic sg $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 , vce(robust)
 sum sevmodanemic if (sg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo sg2: reg sevmodanemic sg $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 & tsd<12 , vce(robust)
 sum sevmodanemic if (sg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo sg3: reg sevmodanemic sg $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 & tdgr_s>=1 & tdgr_s<=4, vce(robust)
 sum sevmodanemic if (sg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo sg4: reg sevmodanemic sg $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 & tdgr_s>=5 & tdgr_s<=14 , vce(robust)
 sum sevmodanemic if (sg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo sg5: reg sevmodanemic sg $contr [pw=dw] if fg==1 & v201>=2 & sp_sb_sg_c==1 & tdgr_s>=15 , vce(robust)
 sum sevmodanemic if (sg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)


eststo tg1: reg sevmodanemic tg $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 , vce(robust)
 sum sevmodanemic if (tg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo tg2:  reg sevmodanemic tg $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 & ttd<12 , vce(robust)
 sum sevmodanemic if (tg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo tg3:  reg sevmodanemic tg $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 & tdgr_t>=1 & tdgr_t<=4, vce(robust)
 sum sevmodanemic if (tg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo tg4:  reg sevmodanemic tg $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 & tdgr_t>=5 & tdgr_t<=14 , vce(robust)
 sum sevmodanemic if (tg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
eststo tg5:  reg sevmodanemic tg $contr [pw=dw] if  fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 & tdgr_t>=15 , vce(robust)
 sum sevmodanemic if (tg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
 esttab fg* sg* tg* using "$output_latex\an_fgsgtg.tex", replace ///
				   label cells(b(star fmt(3)) se(par fmt(3))) sca(fstat) ///
					collabels(none)  stats(N  r2 ym, label("Obs." " $ R^2 $ " "Control mean") fmt(%12.0fc 3) )    ///
					obslast star(* 0.10 ** 0.05 *** .01)  nogap onecell  booktabs nodepvar  ///
					order(fg sg tg) drop(_cons *.year *.CN) ///
					varlabels(sg    "second-born girl \textbar G" ///
                              tg "third-born girl \textbar GG" ) ///
							  mtitle("overall"  "$<$1yr"   "1-4yr" "5-14yrs" "$>=$15 yrs" "overall"  "$<$1yr"   "1-4yr" "5-14yrs" "$>=$15 yrs" "overall"  "$<$1yr"    "1-4yr" "5-14yrs" "$>=$15 yrs") ///
					mgroups( "Dep. var.: =1 if moderate to severely anemic"  , pattern(1 0 0 0 0  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	
					
					
*--------------------------------*
***   TABLE A7 ***  , FEMALE BIRTHS AND MODERATE/SEVERE ANEMIA IN THE HL GROUP CONTROLLING FOR FERTILITY VARIABLES, BY TIME SINCE FIRST BIRTH
*--------------------------------*
estimates clear

	
 eststo fg1: reg sevmodanemic fg $contr v201  if sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (fg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
  eststo fg2:reg sevmodanemic fg $contr pregnant   if sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (fg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
  eststo fg3:reg sevmodanemic fg $contr cbf   if sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (fg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
  eststo fg4:reg sevmodanemic fg $contr v201 pregnant cbf   if sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (fg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 

  eststo sg1: reg sevmodanemic sg $contr v201   if fg==1 & v201>=2 & sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (sg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
   eststo sg2: reg sevmodanemic sg $contr pregnant   if fg==1 & v201>=2 & sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (sg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
   eststo sg3: reg sevmodanemic sg $contr cbf   if fg==1 & v201>=2 & sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (sg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
   eststo sg4: reg sevmodanemic sg $contr v201 pregnant cbf   if fg==1 & v201>=2 & sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (sg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 

  eststo tg1: reg sevmodanemic tg $contr v201   if fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (tg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
 eststo tg2:  reg sevmodanemic tg $contr pregnant   if fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (tg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
 
 eststo tg3: reg sevmodanemic tg $contr cbf   if fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1	[pw=dw] , vce(robust)
 sum `var' if (tg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
 
 eststo tg4: reg sevmodanemic tg $contr v201 pregnant cbf  if fg==1 & sg==1&  v201>=3 & sp_sb_sg_c==1 [pw=dw], vce(robust)
 sum `var' if (tg==0 & e(sample)==1) [aw=dw]
 estadd scalar ym = r(mean)
 
  
esttab fg* sg* tg* using "$output_latex\taban_contr.tex", replace ///
				   label cells(b(star fmt(3)) se(par fmt(3))) sca(fstat) ///
					collabels(none)  stats(N  r2 ym, label("Obs." " $ R^2 $ " "Control mean") fmt(%12.0fc 3) )    ///
					obslast star(* 0.10 ** 0.05 *** .01)  nogap onecell  booktabs nodepvar  nomtitles ///
					order(fg sg tg) drop(_cons *.year *.CN) ///
					varlabels(sg    "second-born girl \textbar G" ///
                              tg "third-born girl \textbar GG" ) ///
              		mgroups( "Dep. var.: =1 if moderate to severely anemic"  , pattern(1 0 0 0 0  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	
 

*--------------------------------*
***   TABLE A8 ***  , SELECTED SUMMARY STATISTICS FOR HL GROUP WITHOUT INDIA
*--------------------------------*

foreach var of varlist edu eduyrs  age agefb termpreg sg contrac wantsmore spacing1_2 anemic sevmodanemic{
	
capture reg `var' fg [pw=dw] if sp_sb_sg_c==1 & CountryName!="India", vce(robust)
outreg2 using "$output_latex\SS_gr1_noinida.xls", nolabel ctitle(`var') se bdec(3) rdec(3) append
}
reg bornkids fg [pw=dw] if sp_sb_sg_c==1 & CountryName!="India" & (wantsnomore==1|femster==1|infert==1), vce(robust)




*--------------------------------*
***   TABLE A9 ***  , ROBUSTNESS CHECKS:HETEROGENEITY OF ALTERNATIVE CHANNELS BY EDUCATION
*--------------------------------*
local varlist "finalsay_ownh beat_any refusesex_any domviol living_pc food_pc"
 estimates clear
 
foreach var in `varlist' {
eststo `var':  reg `var' i.fg##c.eduyrs $contr_noed  [pw=dw] if  resp_ht!=. & edu!=. & agefb!=. & sevmodanemic!=. , vce(robust)
sum `var' if (fg==0 & e(sample)==1) [aw=dw]
estadd scalar ym = r(mean)
}
eststo iron_fp:  reg iron_fp      i.fg##c.eduyrs $contr_noed    [pw=dw] if resp_ht!=. & edu!=. & agefb!=. & sevmodanemic!=.  & v201==1 & td<=36, vce(robust)
sum iron_fp if (fg==0 & e(sample)==1) [aw=dw]
estadd scalar ym = r(mean)

eststo visit:  reg antevisits_2    i.fg##c.eduyrs  $contr_noed    [pw=dw] if resp_ht!=. & edu!=. & agefb!=. & sevmodanemic!=.  & v201==1 & td<=36, vce(robust)
sum antevisits_2 if (fg==0 & e(sample)==1) [aw=dw]
estadd scalar ym = r(mean)

 esttab finalsay_ownh beat_any refusesex_any domviol iron_fp visit food_pc living_pc  using "$output_latex\rob_all_ed_ansample.tex", replace ///
label cells(b(star fmt(3)) se(par fmt(3))) sca(fstat) ///
		  collabels(none)  stats(N  r2 ym, label("Obs." " $ R^2 $ " "Control mean") fmt(%12.0fc 3) )    ///
		   obslast star(* 0.10 ** 0.05 *** .01)  nogap onecell  booktabs  ///
		   keep(1.fg 1.fg#c.eduyrs eduyrs)
 
*--------------------------------*
***   TABLE A10 ***  , EFFECT OF FIRST-BORN GIRL ON ANEMIA FOR THE HIGH SON PREFERENCE AND LOW MATERNAL CARE GROUP, ROBUSTNESS TO CONTROLLING FOR LIVING CONDITIONS/ HOUSEHOLD WEALTH
*--------------------------------*

estimates clear

eststo :reg sevmodanemic fg $contr                          if living_pc!=. & wealth_pc!=. & v191!=. & sp_sb_sg_c==1 [aw=dw], vce(robust)
eststo :reg sevmodanemic fg $contr living_pc                if living_pc!=. & wealth_pc!=. & v191!=. & sp_sb_sg_c==1 [aw=dw] , vce(robust)
eststo :reg sevmodanemic fg $contr nomudfloor pipedw flusht if living_pc!=. & wealth_pc!=. & v191!=. & sp_sb_sg_c==1 [aw=dw] , vce(robust)
eststo :reg sevmodanemic fg $contr wealth_pc                if living_pc!=. & wealth_pc!=. & v191!=. & sp_sb_sg_c==1 [aw=dw] , vce(robust)
eststo :reg sevmodanemic fg $contr v191                     if living_pc!=. & wealth_pc!=. & v191!=. & sp_sb_sg_c==1 [aw=dw] , vce(robust)
 
 
label var living_pc "Living condition index"
label var wealth_pc "Wealth index (constructed)"
label var v191 "Wealth index (DHS)"
label var nomudfloor "Good quality floor"
label var pipedw "Piped water"
label var flusht "Flush toilet"


esttab  using "$output_latex\an_livingpcrob.tex", replace ///
label cells(b(star fmt(3)) se(par fmt(3))) sca(fstat) ///
		  collabels(none)  stats(N  r2 ,label("Obs." " $ R^2 $ ")  fmt(%12.0fc 3) )    ///
		  obslast star(* 0.10 ** 0.05 *** .01) nogap onecell  booktabs  ///
		  keep (fg living_pc nomudfloor pipedw flusht wealth_pc v191)  nodepvar nomtitles ///
		  mgroups( "Dep. var.: =1 if moderate to severely anemic"  , pattern(1 0 0 0 0  ) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	